<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>修改页面页面</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../static/layui/css/layui.css" media="all" th:href="@{/layui/css/layui.css}">
    <link rel="stylesheet" href="../../static/layui/css/admin.css" media="all" th:href="@{/layui/css/admin.css}">
    <link rel="stylesheet" href="../../static/layui/css/login.css" media="all" th:href="@{/layui/css/login.css}">
</head>

<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">
    <div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-forget" style="display: none;">
        <div class="layadmin-user-login-main">
            <div class="layadmin-user-login-box layadmin-user-login-header">
                <h2>修改页面页面</h2>
                <font style="color: red"></font>
            </div>
            <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-password"
                           for="LAY-user-login-password"></label>
                    <input type="password" name="password" id="LAY-user-login-password"
                           placeholder="请输入新密码" class="layui-input">
                    <div id="password_check"></div>
                </div>
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-password"
                           for="LAY-user-login-repass"></label>
                    <input type="password" name="password2" id="LAY-user-login-repass"
                           placeholder="再次输入新密码" class="layui-input">
                    <div id="repass_check"></div>
                </div>
                <div class="layui-form-item">
                    <button id="submit" class="layui-btn layui-btn-fluid" lay-submit
                            lay-filter="LAY-user-reg-submit">提交
                    </button>
                </div>
                <button class="layui-btn layui-btn-fluid" onclick="history.go(-1)">返回</button>
            </div>
        </div>


    </div>


</div>
<script src="../../static/layui/layui.js" th:src="@{/layui/layui.js}"></script>
<script src="../../static/js/jquery-1.8.3.min.js" th:src="@{/js/jquery-1.8.3.min.js}"></script>
<script type="text/javascript" th:inline="javascript">

    function checkPassword() {
        var pattern = /^(?![\d]+$)(?![a-zA-Z]+$)(?![^\da-zA-Z]+$).{6,20}$/;
        var password = $("#LAY-user-login-password").val();
        var flag = pattern.test(password);
        if (!flag) {
            //不合法
            $("#password_check").html('<i style="color: red" class="layui-icon layui-icon-close"></i><span\n' +
                '                            style="color: red;">请输入6-20位数字,字母,特殊字符中两种组合</span>')
        } else {
            //合法
            $("#password_check").html('<i style="color: green" class="layui-icon layui-icon-ok"></i><span\n' +
                '                            style="color: green;">密码格式正确</span>');
        }

        return flag;
    }

    function checkRepass() {
        var pattern = /^(?![\d]+$)(?![a-zA-Z]+$)(?![^\da-zA-Z]+$).{6,20}$/;
        var repass = $("#LAY-user-login-repass").val();
        var password = $("#LAY-user-login-password").val();
        var flag = pattern.test(repass);
        if (!flag) {
            //不合法
            $("#repass_check").html('<i style="color: red" class="layui-icon layui-icon-close"></i><span\n' +
                '                            style="color: red;">请输入6-20位数字,字母,特殊字符中两种组合</span>')
        } else {
            //合法
            if (repass == password) {
                $("#repass_check").html('<i style="color: green" class="layui-icon layui-icon-ok"></i><span\n' +
                    '                            style="color: green;">确定密码正确</span>');
            } else {
                $("#repass_check").html('<i style="color: red" class="layui-icon layui-icon-close"></i><span\n' +
                    '                            style="color: red;">两次密码不一致</span>')
            }

        }

        return flag;
    }

    $("#LAY-user-login-password").blur(checkPassword);
    $("#LAY-user-login-repass").blur(checkRepass);


    layui.use(['form', 'jquery','layer'], function () {
        var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
        var $ = layui.jquery;
        var layer = layui.layer;
        form.on('submit(LAY-user-reg-submit)', function (data) {
            var c2 = checkPassword();
            var c3 = checkRepass();
            if (c2 && c3) {
                $.post(/*[[@{/user/updatePassword}]]*/"/user/updatePassword", data.field, function (data) {
                    if (data.flag) {
                        layer.msg(data.msg);
                        location.href = /*[[@{/logout}]]*/"/logout";
                    } else {
                        layer.msg(data.msg);
                    }
                });
            }
        });
    });
</script>
<script>


    layui.use('form', function () {
        var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功

        //……

        //但是，如果你的HTML是动态生成的，自动渲染就会失效
        //因此你需要在相应的地方，执行下述方法来手动渲染，跟这类似的还有 element.init();
        form.render();//在最后添加这句代码
    });


</script>
</body>
</html>